package cn.tedu.home1ess.admin.content.controller;


import cn.tedu.common.response.JsonResult;
import cn.tedu.home1ess.admin.content.pojo.param.TabooWordsParam;
import cn.tedu.home1ess.admin.content.pojo.vo.TabooWordsCategoryVO;
import cn.tedu.home1ess.admin.content.pojo.vo.TabooWordsVO;
import cn.tedu.home1ess.admin.content.service.ITabooService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/taboowords")
@Validated
@Api(tags = "禁忌词接口")
public class TabooController {
    @Autowired
    private ITabooService tabooService;
    //查询所有的内容
    @GetMapping("tabooAll")
    @ApiOperation("获取全部禁忌词")
    public JsonResult listForContent(){
        List<TabooWordsVO> tabooList=tabooService.listForContent();
        return JsonResult.ok(tabooList);
    }


    //获取一、二级类别,二者请求的内容相同,可以复用
    @GetMapping("categories/{parentId}/sub")
    @ApiOperation("获取禁忌词一、二级类别")
    public  JsonResult listForCategories(@PathVariable Long parentId){
        List<TabooWordsCategoryVO> list=tabooService.listForCategories(parentId);
        return JsonResult.ok(list);

    }

    @PostMapping("add-new")
    @ApiOperation("增加/修改禁忌词")
    public JsonResult addTaboo(TabooWordsParam tabooWordsParam){
        tabooService.addTaboo(tabooWordsParam);
        return JsonResult.ok();
    }

    @GetMapping("{id}/update")
    @ApiOperation("根据id查询禁忌词具体内容方便修改")
    public JsonResult updateCategoryContentById(@PathVariable Long id){
        TabooWordsVO tabooWordsVO=tabooService.updateCategoryContentById(id);
        return JsonResult.ok(tabooWordsVO);
    }

    @PostMapping("{id}/deleteById")
    @ApiOperation("删除禁忌词")
    public JsonResult deleteContentById(@PathVariable Long id){
        tabooService.deleteContentById(id);
        return JsonResult.ok();
    }
}
